<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->

<mat-card appearance="outlined" class="card">
  <div class="card__header">
    <img class="card__header__logo" src="/assets/gravitee-logo-dark-blue.png" alt="Gravitee.io" />
    <div class="card__header__title">Sign Up</div>
    <div class="card__header__subtitle">to access to the APIM Console</div>
  </div>

  <form class="card__form" *ngIf="!signUpSuccess" [formGroup]="signUpForm" (ngSubmit)="signUp()">
    <mat-form-field class="card__form__input">
      <mat-label>First name</mat-label>
      <input matInput type="text" formControlName="firstName" autofocus />
      <mat-error *ngIf="signUpForm.get('firstName').hasError('required')">First name is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input">
      <mat-label>Last name</mat-label>
      <input matInput type="text" formControlName="lastName" />
      <mat-error *ngIf="signUpForm.get('lastName').hasError('required')">Last name is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input">
      <mat-label>Email</mat-label>
      <input matInput type="email" formControlName="email" />
      <mat-error *ngIf="signUpForm.get('email').hasError('required')">Email is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input" *ngFor="let field of customUserFields" formGroupName="customUserFields">
      <mat-label>{{ field.label }}</mat-label>
      <ng-container *ngIf="field.type === 'select'">
        <mat-select [formControlName]="field.key">
          <mat-option *ngFor="let value of field.values" [value]="value">{{ value }}</mat-option>
        </mat-select>
      </ng-container>
      <ng-container *ngIf="field.type === 'input'">
        <input matInput type="text" [formControlName]="field.key" />
      </ng-container>
      <mat-error *ngIf="signUpForm.get('customUserFields.' + field.key).hasError('required')">{{ field.label }} is required.</mat-error>
    </mat-form-field>

    <button type="submit" class="card__form__button" mat-raised-button [disabled]="signUpForm.invalid || signUpInProgress">
      <mat-icon svgIcon="gio:login"></mat-icon>
      Sign up
    </button>

    <p class="card__form__goTo">I have already an account! <a routerLink="/_login">Sign in</a></p>
  </form>

  <ng-container *ngIf="signUpSuccess">
    <gio-banner-success>
      Thank you for signing up!
      <span gioBannerBody>You will receive an email with a link to activate your account.</span>
    </gio-banner-success>
    <p class="card__form__signIn">Go to <a routerLink="/_login">Sign in</a></p>
  </ng-container>
</mat-card>
